<!DOCTYPE html><html><head>
      <title>js-arr</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css">
      
      
      
      
      
      
      
      
      
      <style>
      /**
 * prism.js Github theme based on GitHub's theme.
 * @author Sam Clarke
 */
code[class*="language-"],
pre[class*="language-"] {
  color: #333;
  background: none;
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.4;

  -moz-tab-size: 8;
  -o-tab-size: 8;
  tab-size: 8;

  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
}

/* Code blocks */
pre[class*="language-"] {
  padding: .8em;
  overflow: auto;
  /* border: 1px solid #ddd; */
  border-radius: 3px;
  /* background: #fff; */
  background: #f5f5f5;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
  padding: .1em;
  border-radius: .3em;
  white-space: normal;
  background: #f5f5f5;
}

.token.comment,
.token.blockquote {
  color: #969896;
}

.token.cdata {
  color: #183691;
}

.token.doctype,
.token.punctuation,
.token.variable,
.token.macro.property {
  color: #333;
}

.token.operator,
.token.important,
.token.keyword,
.token.rule,
.token.builtin {
  color: #a71d5d;
}

.token.string,
.token.url,
.token.regex,
.token.attr-value {
  color: #183691;
}

.token.property,
.token.number,
.token.boolean,
.token.entity,
.token.atrule,
.token.constant,
.token.symbol,
.token.command,
.token.code {
  color: #0086b3;
}

.token.tag,
.token.selector,
.token.prolog {
  color: #63a35c;
}

.token.function,
.token.namespace,
.token.pseudo-element,
.token.class,
.token.class-name,
.token.pseudo-class,
.token.id,
.token.url-reference .token.variable,
.token.attr-name {
  color: #795da3;
}

.token.entity {
  cursor: help;
}

.token.title,
.token.title .token.punctuation {
  font-weight: bold;
  color: #1d3e81;
}

.token.list {
  color: #ed6a43;
}

.token.inserted {
  background-color: #eaffea;
  color: #55a532;
}

.token.deleted {
  background-color: #ffecec;
  color: #bd2c00;
}

.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}


/* JSON */
.language-json .token.property {
  color: #183691;
}

.language-markup .token.tag .token.punctuation {
  color: #333;
}

/* CSS */
code.language-css,
.language-css .token.function {
  color: #0086b3;
}

/* YAML */
.language-yaml .token.atrule {
  color: #63a35c;
}

code.language-yaml {
  color: #183691;
}

/* Ruby */
.language-ruby .token.function {
  color: #333;
}

/* Markdown */
.language-markdown .token.url {
  color: #795da3;
}

/* Makefile */
.language-makefile .token.symbol {
  color: #795da3;
}

.language-makefile .token.variable {
  color: #183691;
}

.language-makefile .token.builtin {
  color: #0086b3;
}

/* Bash */
.language-bash .token.keyword {
  color: #0086b3;
}

/* highlight */
pre[data-line] {
  position: relative;
  padding: 1em 0 1em 3em;
}
pre[data-line] .line-highlight-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  background-color: transparent;
  display: block;
  width: 100%;
}

pre[data-line] .line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  padding: inherit 0;
  margin-top: 1em;
  background: hsla(24, 20%, 50%,.08);
  background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
  pointer-events: none;
  line-height: inherit;
  white-space: pre;
}

pre[data-line] .line-highlight:before, 
pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-start);
  position: absolute;
  top: .4em;
  left: .6em;
  min-width: 1em;
  padding: 0 .5em;
  background-color: hsla(24, 20%, 50%,.4);
  color: hsl(24, 20%, 95%);
  font: bold 65%/1.5 sans-serif;
  text-align: center;
  vertical-align: .3em;
  border-radius: 999px;
  text-shadow: none;
  box-shadow: 0 1px white;
}

pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-end);
  top: auto;
  bottom: .4em;
}html body{font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ul,html body>ol{margin-bottom:16px}html body ul,html body ol{padding-left:2em}html body ul.no-list,html body ol.no-list{padding:0;list-style-type:none}html body ul ul,html body ul ol,html body ol ol,html body ol ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:bold;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em !important;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::before,html body code::after{letter-spacing:-0.2em;content:"\00a0"}html body pre>code{padding:0;margin:0;font-size:.85em !important;word-break:normal;white-space:pre;background:transparent;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;font-size:.85em !important;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:before,html body pre tt:before,html body pre code:after,html body pre tt:after{content:normal}html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body pre,html body code{word-wrap:break-word;white-space:pre}}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview .pagebreak,.markdown-preview .newpage{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center !important}.markdown-preview:not([for="preview"]) .code-chunk .btn-group{display:none}.markdown-preview:not([for="preview"]) .code-chunk .status{display:none}.markdown-preview:not([for="preview"]) .code-chunk .output-div{margin-bottom:16px}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0}@media screen and (min-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{font-size:14px !important;padding:1em}}@media print{html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,0.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{padding:0 1.6em;margin-top:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc li{margin-bottom:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{list-style-type:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% -  300px);padding:2em calc(50% - 457px -  150px);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
/* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */

      </style>
    </head>
    <body for="html-export">
      <div class="mume markdown-preview  ">
      <h3 class="mume-header" id="js%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E5%A4%A7%E5%85%A8">js&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x5927;&#x5168;</h3>

<h4 class="mume-header" id="1-javascript%E4%B8%AD%E5%88%9B%E5%BB%BA%E6%95%B0%E7%BB%84%E6%9C%89%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F">1. JavaScript&#x4E2D;&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;</h4>

<p>&#xFF08;&#x4E00;&#xFF09;&#x4F7F;&#x7528; Array &#x6784;&#x9020;&#x51FD;&#x6570;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Array</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;</span>
<span class="token keyword">var</span> arr2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Array</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5305;&#x542B;20&#x9879;&#x7684;&#x6570;&#x7EC4;</span>
<span class="token keyword">var</span> arr3 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Array</span><span class="token punctuation">(</span><span class="token string">&quot;lily&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;lucy&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Tom&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5305;&#x542B;3&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6570;&#x7EC4;</span>
</pre><p>&#xFF08;&#x4E8C;&#xFF09;&#x4F7F;&#x7528;&#x6570;&#x7EC4;&#x5B57;&#x9762;&#x91CF;&#x8868;&#x793A;&#x6CD5;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr4 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;</span>
<span class="token keyword">var</span> arr5 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">20</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5305;&#x542B;1&#x9879;&#x7684;&#x6570;&#x7EC4;</span>
<span class="token keyword">var</span> arr6 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;lily&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;lucy&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Tom&quot;</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5305;&#x542B;3&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6570;&#x7EC4;</span>
</pre><p>&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;&#x6709;&#x6570;&#x7EC4;&#x539F;&#x578B;&#x65B9;&#x6CD5;&#xFF0C;&#x4E5F;&#x6709;&#x4ECE;object&#x5BF9;&#x8C61;&#x7EE7;&#x627F;&#x6765;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x53EA;&#x4ECB;&#x7ECD;&#x6570;&#x7EC4;&#x7684;&#x539F;&#x578B;&#x65B9;&#x6CD5;&#xFF0C;&#x6570;&#x7EC4;&#x539F;&#x578B;&#x65B9;&#x6CD5;&#x4E3B;&#x8981;&#x6709;&#x4EE5;&#x4E0B;&#x8FD9;&#x4E9B;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token function">&#x548C;pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">shift</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#x548C; <span class="token function">unshift</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">concat</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">slice</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">splice</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x548C; <span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">filter</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">every</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">some</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
<span class="token function">reduce</span><span class="token punctuation">(</span><span class="token punctuation">)</span>&#x548C; <span class="token function">reduceRight</span><span class="token punctuation">(</span><span class="token punctuation">)</span> &#xFF08;<span class="token constant">ES5</span>&#x65B0;&#x589E;&#xFF09;
</pre><p>&#x4E0B;&#x9762;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x5404;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x57FA;&#x672C;&#x529F;&#x80FD;&#x3002;</p>
<p>1&#x3001;join()<br>
join(separator): &#x5C06;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x7EC4;&#x8D77;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4EE5;separator&#x4E3A;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7701;&#x7565;&#x7684;&#x8BDD;&#x5219;&#x7528;&#x9ED8;&#x8BA4;&#x7528;&#x9017;&#x53F7;&#x4E3A;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x53EA;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x5373;&#x5206;&#x9694;&#x7B26;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 1,2,3</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&quot;-&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 1-2-3</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [1, 2, 3]&#xFF08;&#x539F;&#x6570;&#x7EC4;&#x4E0D;&#x53D8;&#xFF09;</span>
</pre><p>&#x901A;&#x8FC7;join()&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x91CD;&#x590D;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x53EA;&#x9700;&#x4F20;&#x5165;&#x5B57;&#x7B26;&#x4E32;&#x4EE5;&#x53CA;&#x91CD;&#x590D;&#x7684;&#x6B21;&#x6570;&#xFF0C;&#x5C31;&#x80FD;&#x8FD4;&#x56DE;&#x91CD;&#x590D;&#x540E;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x51FD;&#x6570;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">repeatString</span><span class="token punctuation">(</span><span class="token parameter">str<span class="token punctuation">,</span> n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Array</span><span class="token punctuation">(</span>n <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">repeatString</span><span class="token punctuation">(</span><span class="token string">&quot;abc&quot;</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// abcabcabc</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">repeatString</span><span class="token punctuation">(</span><span class="token string">&quot;Hi&quot;</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// HiHiHiHiHi</span>
</pre><p>2&#x3001;push()&#x548C;pop()</p>
<p>push(): &#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x628A;&#x5B83;&#x4EEC;&#x9010;&#x4E2A;&#x6DFB;&#x52A0;&#x5230;&#x6570;&#x7EC4;&#x672B;&#x5C3E;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#x3002;<br>
pop()&#xFF1A;&#x6570;&#x7EC4;&#x672B;&#x5C3E;&#x79FB;&#x9664;&#x6700;&#x540E;&#x4E00;&#x9879;&#xFF0C;&#x51CF;&#x5C11;&#x6570;&#x7EC4;&#x7684; length &#x503C;&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x79FB;&#x9664;&#x7684;&#x9879;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;Lily&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;lucy&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Tom&quot;</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> count <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token string">&quot;Jack&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Sean&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>count<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 5</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [&quot;Lily&quot;, &quot;lucy&quot;, &quot;Tom&quot;, &quot;Jack&quot;, &quot;Sean&quot;]</span>
<span class="token keyword">var</span> item <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Sean</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [&quot;Lily&quot;, &quot;lucy&quot;, &quot;Tom&quot;, &quot;Jack&quot;]</span>
</pre><p>3&#x3001;shift() &#x548C; unshift()</p>
<p>shift()&#xFF1A;&#x5220;&#x9664;&#x539F;&#x6570;&#x7EC4;&#x7B2C;&#x4E00;&#x9879;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x5220;&#x9664;&#x5143;&#x7D20;&#x7684;&#x503C;&#xFF1B;&#x5982;&#x679C;&#x6570;&#x7EC4;&#x4E3A;&#x7A7A;&#x5219;&#x8FD4;&#x56DE;undefined &#x3002;<br>
unshift:&#x5C06;&#x53C2;&#x6570;&#x6DFB;&#x52A0;&#x5230;&#x539F;&#x6570;&#x7EC4;&#x5F00;&#x5934;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6; &#x3002;<br>
&#x8FD9;&#x7EC4;&#x65B9;&#x6CD5;&#x548C;&#x4E0A;&#x9762;&#x7684;push()&#x548C;pop()&#x65B9;&#x6CD5;&#x6B63;&#x597D;&#x5BF9;&#x5E94;&#xFF0C;&#x4E00;&#x4E2A;&#x662F;&#x64CD;&#x4F5C;&#x6570;&#x7EC4;&#x7684;&#x5F00;&#x5934;&#xFF0C;&#x4E00;&#x4E2A;&#x662F;&#x64CD;&#x4F5C;&#x6570;&#x7EC4;&#x7684;&#x7ED3;&#x5C3E;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;Lily&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;lucy&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Tom&quot;</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> count <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">unshift</span><span class="token punctuation">(</span><span class="token string">&quot;Jack&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;Sean&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>count<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 5</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[&quot;Jack&quot;, &quot;Sean&quot;, &quot;Lily&quot;, &quot;lucy&quot;, &quot;Tom&quot;]</span>
<span class="token keyword">var</span> item <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">shift</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Jack</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [&quot;Sean&quot;, &quot;Lily&quot;, &quot;lucy&quot;, &quot;Tom&quot;]</span>
</pre><p>4&#x3001;sort()</p>
<p>sort()&#xFF1A;&#x6309;&#x5347;&#x5E8F;&#x6392;&#x5217;&#x6570;&#x7EC4;&#x9879;&#x2014;&#x2014;&#x5373;&#x6700;&#x5C0F;&#x7684;&#x503C;&#x4F4D;&#x4E8E;&#x6700;&#x524D;&#x9762;&#xFF0C;&#x6700;&#x5927;&#x7684;&#x503C;&#x6392;&#x5728;&#x6700;&#x540E;&#x9762;&#x3002;<br>
&#x5728;&#x6392;&#x5E8F;&#x65F6;&#xFF0C;sort()&#x65B9;&#x6CD5;&#x4F1A;&#x8C03;&#x7528;&#x6BCF;&#x4E2A;&#x6570;&#x7EC4;&#x9879;&#x7684; toString()&#x8F6C;&#x578B;&#x65B9;&#x6CD5;&#xFF0C;&#x7136;&#x540E;&#x6BD4;&#x8F83;&#x5F97;&#x5230;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4EE5;&#x786E;&#x5B9A;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x3002;&#x5373;&#x4F7F;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x90FD;&#x662F;&#x6570;&#x503C;&#xFF0C; sort()&#x65B9;&#x6CD5;&#x6BD4;&#x8F83;&#x7684;&#x4E5F;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x56E0;&#x6B64;&#x4F1A;&#x51FA;&#x73B0;&#x4EE5;&#x4E0B;&#x7684;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr1 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;d&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr1<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;]</span>
arr2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">51</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [13, 24, 3, 51]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [13, 24, 3, 51](&#x5143;&#x6570;&#x7EC4;&#x88AB;&#x6539;&#x53D8;)</span>
</pre><p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x4E0A;&#x8FF0;&#x95EE;&#x9898;&#xFF0C;sort()&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x4EE5;&#x4FBF;&#x6211;&#x4EEC;&#x6307;&#x5B9A;&#x54EA;&#x4E2A;&#x503C;&#x4F4D;&#x4E8E;&#x54EA;&#x4E2A;&#x503C;&#x7684;&#x524D;&#x9762;&#x3002;&#x6BD4;&#x8F83;&#x51FD;&#x6570;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x5E94;&#x8BE5;&#x4F4D;&#x4E8E;&#x7B2C;&#x4E8C;&#x4E2A;&#x4E4B;&#x524D;&#x5219;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x8D1F;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x76F8;&#x7B49;&#x5219;&#x8FD4;&#x56DE; 0&#xFF0C;&#x5982;&#x679C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x5E94;&#x8BE5;&#x4F4D;&#x4E8E;&#x7B2C;&#x4E8C;&#x4E2A;&#x4E4B;&#x540E;&#x5219;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6B63;&#x6570;&#x3002;&#x4EE5;&#x4E0B;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x6BD4;&#x8F83;&#x51FD;&#x6570;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">compare</span><span class="token punctuation">(</span><span class="token parameter">value1<span class="token punctuation">,</span> value2</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>value1 <span class="token operator">&lt;</span> value2<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>value1 <span class="token operator">&gt;</span> value2<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
arr2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">51</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>compare<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [3, 13, 24, 51]</span>
</pre><p>&#x5982;&#x679C;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x6BD4;&#x8F83;&#x51FD;&#x6570;&#x4EA7;&#x751F;&#x964D;&#x5E8F;&#x6392;&#x5E8F;&#x7684;&#x7ED3;&#x679C;&#xFF0C;&#x53EA;&#x8981;&#x4EA4;&#x6362;&#x6BD4;&#x8F83;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#x5373;&#x53EF;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">compare</span><span class="token punctuation">(</span><span class="token parameter">value1<span class="token punctuation">,</span> value2</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>value1 <span class="token operator">&lt;</span> value2<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>value1 <span class="token operator">&gt;</span> value2<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
arr2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">51</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>compare<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [51, 24, 13, 3]</span>
</pre><p>5&#x3001;reverse()</p>
<p>reverse()&#xFF1A;&#x53CD;&#x8F6C;&#x6570;&#x7EC4;&#x9879;&#x7684;&#x987A;&#x5E8F;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token number">24</span><span class="token punctuation">,</span> <span class="token number">51</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[3, 51, 24, 13]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[3, 51, 24, 13](&#x539F;&#x6570;&#x7EC4;&#x6539;&#x53D8;)</span>
</pre><p>6&#x3001;concat()</p>
<p>concat() &#xFF1A;&#x5C06;&#x53C2;&#x6570;&#x6DFB;&#x52A0;&#x5230;&#x539F;&#x6570;&#x7EC4;&#x4E2D;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4F1A;&#x5148;&#x521B;&#x5EFA;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x4E00;&#x4E2A;&#x526F;&#x672C;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x63A5;&#x6536;&#x5230;&#x7684;&#x53C2;&#x6570;&#x6DFB;&#x52A0;&#x5230;&#x8FD9;&#x4E2A;&#x526F;&#x672C;&#x7684;&#x672B;&#x5C3E;&#xFF0C;&#x6700;&#x540E;&#x8FD4;&#x56DE;&#x65B0;&#x6784;&#x5EFA;&#x7684;&#x6570;&#x7EC4;&#x3002;&#x5728;&#x6CA1;&#x6709;&#x7ED9; concat()&#x65B9;&#x6CD5;&#x4F20;&#x9012;&#x53C2;&#x6570;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5B83;&#x53EA;&#x662F;&#x590D;&#x5236;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x5E76;&#x8FD4;&#x56DE;&#x526F;&#x672C;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrCopy <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 3, 5, 7, 9, 11, 13]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [1, 3, 5, 7](&#x539F;&#x6570;&#x7EC4;&#x672A;&#x88AB;&#x4FEE;&#x6539;)</span>
</pre><p>&#x4ECE;&#x4E0A;&#x9762;&#x6D4B;&#x8BD5;&#x7ED3;&#x679C;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF1A;&#x4F20;&#x5165;&#x7684;&#x4E0D;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x628A;&#x53C2;&#x6570;&#x6DFB;&#x52A0;&#x5230;&#x6570;&#x7EC4;&#x540E;&#x9762;&#xFF0C;&#x5982;&#x679C;&#x4F20;&#x5165;&#x7684;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x5219;&#x5C06;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5404;&#x4E2A;&#x9879;&#x6DFB;&#x52A0;&#x5230;&#x6570;&#x7EC4;&#x4E2D;&#x3002;&#x4F46;&#x662F;&#x5982;&#x679C;&#x4F20;&#x5165;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x5462;&#xFF1F;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arrCopy2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 3, 5, 7, 9, Array[2]]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy2<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[11, 13]</span>
</pre><p>&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;arrCopy2&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E94;&#x9879;&#x662F;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x4E24;&#x9879;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;concat&#x65B9;&#x6CD5;&#x53EA;&#x80FD;&#x5C06;&#x4F20;&#x5165;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x6DFB;&#x52A0;&#x5230;&#x6570;&#x7EC4;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x4F20;&#x5165;&#x6570;&#x7EC4;&#x4E2D;&#x6709;&#x4E9B;&#x9879;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x90A3;&#x4E48;&#x4E5F;&#x4F1A;&#x628A;&#x8FD9;&#x4E00;&#x6570;&#x7EC4;&#x9879;&#x5F53;&#x4F5C;&#x4E00;&#x9879;&#x6DFB;&#x52A0;&#x5230;arrCopy2&#x4E2D;&#x3002;</p>
<p>7&#x3001;slice()</p>
<p>slice()&#xFF1A;&#x8FD4;&#x56DE;&#x4ECE;&#x539F;&#x6570;&#x7EC4;&#x4E2D;&#x6307;&#x5B9A;&#x5F00;&#x59CB;&#x4E0B;&#x6807;&#x5230;&#x7ED3;&#x675F;&#x4E0B;&#x6807;&#x4E4B;&#x95F4;&#x7684;&#x9879;&#x7EC4;&#x6210;&#x7684;&#x65B0;&#x6570;&#x7EC4;&#x3002;slice()&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E00;&#x6216;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5373;&#x8981;&#x8FD4;&#x56DE;&#x9879;&#x7684;&#x8D77;&#x59CB;&#x548C;&#x7ED3;&#x675F;&#x4F4D;&#x7F6E;&#x3002;&#x5728;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C; slice()&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4ECE;&#x8BE5;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x5F00;&#x59CB;&#x5230;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x672B;&#x5C3E;&#x7684;&#x6240;&#x6709;&#x9879;&#x3002;&#x5982;&#x679C;&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x8D77;&#x59CB;&#x548C;&#x7ED3;&#x675F;&#x4F4D;&#x7F6E;&#x4E4B;&#x95F4;&#x7684;&#x9879;&#x2014;&#x2014;&#x4F46;&#x4E0D;&#x5305;&#x62EC;&#x7ED3;&#x675F;&#x4F4D;&#x7F6E;&#x7684;&#x9879;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">11</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrCopy <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrCopy2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrCopy3 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrCopy4 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 3, 5, 7, 9, 11](&#x539F;&#x6570;&#x7EC4;&#x6CA1;&#x53D8;)</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[3, 5, 7, 9, 11]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[3, 5, 7]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy3<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[3, 5, 7]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrCopy4<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[5, 7, 9]</span>
</pre><p>arrCopy&#x53EA;&#x8BBE;&#x7F6E;&#x4E86;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8D77;&#x59CB;&#x4E0B;&#x6807;&#x4E3A;1&#xFF0C;&#x6240;&#x4EE5;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x7EC4;&#x4E3A;&#x4E0B;&#x6807;1&#xFF08;&#x5305;&#x62EC;&#x4E0B;&#x6807;1&#xFF09;&#x5F00;&#x59CB;&#x5230;&#x6570;&#x7EC4;&#x6700;&#x540E;&#x3002;<br>
arrCopy2&#x8BBE;&#x7F6E;&#x4E86;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x8D77;&#x59CB;&#x4E0B;&#x6807;&#xFF08;&#x5305;&#x62EC;1&#xFF09;&#x5F00;&#x59CB;&#x5230;&#x7EC8;&#x6B62;&#x4E0B;&#x6807;&#xFF08;&#x4E0D;&#x5305;&#x62EC;4&#xFF09;&#x7684;&#x5B50;&#x6570;&#x7EC4;&#x3002;<br>
arrCopy3&#x8BBE;&#x7F6E;&#x4E86;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7EC8;&#x6B62;&#x4E0B;&#x6807;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x5F53;&#x51FA;&#x73B0;&#x8D1F;&#x6570;&#x65F6;&#xFF0C;&#x5C06;&#x8D1F;&#x6570;&#x52A0;&#x4E0A;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x7684;&#x503C;&#xFF08;6&#xFF09;&#x6765;&#x66FF;&#x6362;&#x8BE5;&#x4F4D;&#x7F6E;&#x7684;&#x6570;&#xFF0C;&#x56E0;&#x6B64;&#x5C31;&#x662F;&#x4ECE;1&#x5F00;&#x59CB;&#x5230;4&#xFF08;&#x4E0D;&#x5305;&#x62EC;&#xFF09;&#x7684;&#x5B50;&#x6570;&#x7EC4;&#x3002;<br>
arrCopy4&#x4E2D;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x8D1F;&#x6570;&#xFF0C;&#x6240;&#x4EE5;&#x90FD;&#x52A0;&#x4E0A;&#x6570;&#x7EC4;&#x957F;&#x5EA6;6&#x8F6C;&#x6362;&#x6210;&#x6B63;&#x6570;&#xFF0C;&#x56E0;&#x6B64;&#x76F8;&#x5F53;&#x4E8E;slice(2,5)&#x3002;</p>
<p>8&#x3001;splice()</p>
<p>splice()&#xFF1A;&#x5F88;&#x5F3A;&#x5927;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x6709;&#x5F88;&#x591A;&#x79CD;&#x7528;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5220;&#x9664;&#x3001;&#x63D2;&#x5165;&#x548C;&#x66FF;&#x6362;&#x3002;</p>
<p>&#x5220;&#x9664;&#xFF1A;&#x53EF;&#x4EE5;&#x5220;&#x9664;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9879;&#xFF0C;&#x53EA;&#x9700;&#x6307;&#x5B9A; 2 &#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8981;&#x5220;&#x9664;&#x7684;&#x7B2C;&#x4E00;&#x9879;&#x7684;&#x4F4D;&#x7F6E;&#x548C;&#x8981;&#x5220;&#x9664;&#x7684;&#x9879;&#x6570;&#x3002;&#x4F8B;&#x5982;&#xFF0C; splice(0,2)&#x4F1A;&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x524D;&#x4E24;&#x9879;&#x3002;</p>
<p>&#x63D2;&#x5165;&#xFF1A;&#x53EF;&#x4EE5;&#x5411;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x63D2;&#x5165;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9879;&#xFF0C;&#x53EA;&#x9700;&#x63D0;&#x4F9B; 3 &#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;&#x3001; 0&#xFF08;&#x8981;&#x5220;&#x9664;&#x7684;&#x9879;&#x6570;&#xFF09;&#x548C;&#x8981;&#x63D2;&#x5165;&#x7684;&#x9879;&#x3002;&#x4F8B;&#x5982;&#xFF0C;splice(2,0,4,6)&#x4F1A;&#x4ECE;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x7684;&#x4F4D;&#x7F6E; 2 &#x5F00;&#x59CB;&#x63D2;&#x5165;4&#x548C;6&#x3002;<br>
&#x66FF;&#x6362;&#xFF1A;&#x53EF;&#x4EE5;&#x5411;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x63D2;&#x5165;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9879;&#xFF0C;&#x4E14;&#x540C;&#x65F6;&#x5220;&#x9664;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9879;&#xFF0C;&#x53EA;&#x9700;&#x6307;&#x5B9A; 3 &#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;&#x3001;&#x8981;&#x5220;&#x9664;&#x7684;&#x9879;&#x6570;&#x548C;&#x8981;&#x63D2;&#x5165;&#x7684;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9879;&#x3002;&#x63D2;&#x5165;&#x7684;&#x9879;&#x6570;&#x4E0D;&#x5FC5;&#x4E0E;&#x5220;&#x9664;&#x7684;&#x9879;&#x6570;&#x76F8;&#x7B49;&#x3002;&#x4F8B;&#x5982;&#xFF0C;splice (2,1,4,6)&#x4F1A;&#x5220;&#x9664;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x4F4D;&#x7F6E; 2 &#x7684;&#x9879;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x4ECE;&#x4F4D;&#x7F6E; 2 &#x5F00;&#x59CB;&#x63D2;&#x5165;4&#x548C;6&#x3002;</p>
<p>splice()&#x65B9;&#x6CD5;&#x59CB;&#x7EC8;&#x90FD;&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8BE5;&#x6570;&#x7EC4;&#x4E2D;&#x5305;&#x542B;&#x4ECE;&#x539F;&#x59CB;&#x6570;&#x7EC4;&#x4E2D;&#x5220;&#x9664;&#x7684;&#x9879;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5220;&#x9664;&#x4EFB;&#x4F55;&#x9879;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">11</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arrRemoved <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[5, 7, 9, 11]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrRemoved<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 3]</span>
<span class="token keyword">var</span> arrRemoved2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [5, 7, 4, 6, 9, 11]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrRemoved2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// []</span>
<span class="token keyword">var</span> arrRemoved3 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// [5, 2, 4, 4, 6, 9, 11]</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arrRemoved3<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[7]</span>
</pre><p>9&#x3001;indexOf()&#x548C; lastIndexOf()</p>
<p>indexOf()&#xFF1A;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8981;&#x67E5;&#x627E;&#x7684;&#x9879;&#x548C;&#xFF08;&#x53EF;&#x9009;&#x7684;&#xFF09;&#x8868;&#x793A;&#x67E5;&#x627E;&#x8D77;&#x70B9;&#x4F4D;&#x7F6E;&#x7684;&#x7D22;&#x5F15;&#x3002;&#x5176;&#x4E2D;&#xFF0C; &#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x5F00;&#x5934;&#xFF08;&#x4F4D;&#x7F6E; 0&#xFF09;&#x5F00;&#x59CB;&#x5411;&#x540E;&#x67E5;&#x627E;&#x3002;<br>
lastIndexOf&#xFF1A;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x8981;&#x67E5;&#x627E;&#x7684;&#x9879;&#x548C;&#xFF08;&#x53EF;&#x9009;&#x7684;&#xFF09;&#x8868;&#x793A;&#x67E5;&#x627E;&#x8D77;&#x70B9;&#x4F4D;&#x7F6E;&#x7684;&#x7D22;&#x5F15;&#x3002;&#x5176;&#x4E2D;&#xFF0C; &#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x672B;&#x5C3E;&#x5F00;&#x59CB;&#x5411;&#x524D;&#x67E5;&#x627E;&#x3002;</p>
<p>&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x8FD4;&#x56DE;&#x8981;&#x67E5;&#x627E;&#x7684;&#x9879;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x6216;&#x8005;&#x5728;&#x6CA1;&#x627E;&#x5230;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD4;&#x56DE;&#xF02D;1&#x3002;&#x5728;&#x6BD4;&#x8F83;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E0E;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x65F6;&#xFF0C;&#x4F1A;&#x4F7F;&#x7528;&#x5168;&#x7B49;&#x64CD;&#x4F5C;&#x7B26;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//2</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//5</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//2</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//2</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span><span class="token string">&quot;5&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//-1</span>
</pre><p>10&#x3001;forEach()</p>
<p>forEach()&#xFF1A;&#x5BF9;&#x6570;&#x7EC4;&#x8FDB;&#x884C;&#x904D;&#x5386;&#x5FAA;&#x73AF;&#xFF0C;&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#x3002;&#x53C2;&#x6570;&#x90FD;&#x662F;function&#x7C7B;&#x578B;&#xFF0C;&#x9ED8;&#x8BA4;&#x6709;&#x4F20;&#x53C2;&#xFF0C;&#x53C2;&#x6570;&#x5206;&#x522B;&#x4E3A;&#xFF1A;&#x904D;&#x5386;&#x7684;&#x6570;&#x7EC4;&#x5185;&#x5BB9;&#xFF1B;&#x7B2C;&#x5BF9;&#x5E94;&#x7684;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#xFF0C;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
arr<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> index<span class="token punctuation">,</span> a</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>x <span class="token operator">+</span> <span class="token string">&apos;|&apos;</span> <span class="token operator">+</span> index <span class="token operator">+</span> <span class="token string">&apos;|&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>a <span class="token operator">===</span> arr<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// &#x8F93;&#x51FA;&#x4E3A;&#xFF1A;</span>
<span class="token comment">// 1|0|true</span>
<span class="token comment">// 2|1|true</span>
<span class="token comment">// 3|2|true</span>
<span class="token comment">// 4|3|true</span>
<span class="token comment">// 5|4|true</span>
</pre><p>11&#x3001;map()</p>
<p>map()&#xFF1A;&#x6307;&#x201C;&#x6620;&#x5C04;&#x201D;&#xFF0C;&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x6BCF;&#x6B21;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x7ED3;&#x679C;&#x7EC4;&#x6210;&#x7684;&#x6570;&#x7EC4;&#x3002;<br>
&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x5229;&#x7528;map&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E2A;&#x6570;&#x6C42;&#x5E73;&#x65B9;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arr2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">item</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">return</span> item<span class="token operator">*</span>item<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 4, 9, 16, 25]</span>
</pre><p>12&#x3001;filter()</p>
<p>filter()&#xFF1A;&#x201C;&#x8FC7;&#x6EE4;&#x201D;&#x529F;&#x80FD;&#xFF0C;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x6EE1;&#x8DB3;&#x8FC7;&#x6EE4;&#x6761;&#x4EF6;&#x7EC4;&#x6210;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arr2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> index <span class="token operator">%</span> <span class="token number">3</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token operator">||</span> x <span class="token operator">&gt;=</span> <span class="token number">8</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//[1, 4, 7, 8, 9, 10]</span>
</pre><p>13&#x3001;every()</p>
<p>every()&#xFF1A;&#x5224;&#x65AD;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x90FD;&#x662F;&#x5426;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF0C;&#x53EA;&#x6709;&#x6240;&#x6709;&#x9879;&#x90FD;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF0C;&#x624D;&#x4F1A;&#x8FD4;&#x56DE;true&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arr2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">every</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">&lt;</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//true</span>
<span class="token keyword">var</span> arr3 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">every</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">&lt;</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr3<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
</pre><p>14&#x3001;some()</p>
<p>some()&#xFF1A;&#x5224;&#x65AD;&#x6570;&#x7EC4;&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x7684;&#x9879;&#xFF0C;&#x53EA;&#x8981;&#x6709;&#x4E00;&#x9879;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF0C;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE;true&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> arr2 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">some</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">&lt;</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//true</span>
<span class="token keyword">var</span> arr3 <span class="token operator">=</span> arr<span class="token punctuation">.</span><span class="token function">some</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">x</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> x <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr3<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
</pre><p>15&#x3001;reduce()&#x548C; reduceRight()</p>
<p>&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x4F1A;&#x5B9E;&#x73B0;&#x8FED;&#x4EE3;&#x6570;&#x7EC4;&#x7684;&#x6240;&#x6709;&#x9879;&#xFF0C;&#x7136;&#x540E;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x6700;&#x7EC8;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#x3002;reduce()&#x65B9;&#x6CD5;&#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x9879;&#x5F00;&#x59CB;&#xFF0C;&#x9010;&#x4E2A;&#x904D;&#x5386;&#x5230;&#x6700;&#x540E;&#x3002;&#x800C; reduceRight()&#x5219;&#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x6700;&#x540E;&#x4E00;&#x9879;&#x5F00;&#x59CB;&#xFF0C;&#x5411;&#x524D;&#x904D;&#x5386;&#x5230;&#x7B2C;&#x4E00;&#x9879;&#x3002;</p>
<p>&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x4E00;&#x4E2A;&#x5728;&#x6BCF;&#x4E00;&#x9879;&#x4E0A;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x548C;&#xFF08;&#x53EF;&#x9009;&#x7684;&#xFF09;&#x4F5C;&#x4E3A;&#x5F52;&#x5E76;&#x57FA;&#x7840;&#x7684;&#x521D;&#x59CB;&#x503C;&#x3002;</p>
<p>&#x4F20;&#x7ED9; reduce()&#x548C; reduceRight()&#x7684;&#x51FD;&#x6570;&#x63A5;&#x6536; 4 &#x4E2A;&#x53C2;&#x6570;&#xFF1A;&#x524D;&#x4E00;&#x4E2A;&#x503C;&#x3001;&#x5F53;&#x524D;&#x503C;&#x3001;&#x9879;&#x7684;&#x7D22;&#x5F15;&#x548C;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#x3002;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x7684;&#x4EFB;&#x4F55;&#x503C;&#x90FD;&#x4F1A;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x81EA;&#x52A8;&#x4F20;&#x7ED9;&#x4E0B;&#x4E00;&#x9879;&#x3002;&#x7B2C;&#x4E00;&#x6B21;&#x8FED;&#x4EE3;&#x53D1;&#x751F;&#x5728;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E8C;&#x9879;&#x4E0A;&#xFF0C;&#x56E0;&#x6B64;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x9879;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E8C;&#x9879;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x7528;reduce()&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x6C42;&#x548C;&#xFF0C;&#x6570;&#x7EC4;&#x4E00;&#x5F00;&#x59CB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x521D;&#x59CB;&#x503C;10&#x3002;</p>
<pre data-role="codeBlock" data-info="javascript" class="language-javascript"><span class="token keyword">var</span> values <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> sum <span class="token operator">=</span> values<span class="token punctuation">.</span><span class="token function">reduceRight</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">prev<span class="token punctuation">,</span> cur<span class="token punctuation">,</span> index<span class="token punctuation">,</span> array</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">return</span> prev <span class="token operator">+</span> cur<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>sum<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//25</span>
</pre>
      </div>
      
      
    
    
    
    
    
    
    
    
  
    </body></html>